let map

require([
	'esri/map',
	'esri/layers/WMTSLayer',
	'esri/layers/WMTSLayerInfo',
	'esri/layers/TileInfo',
	'esri/SpatialReference',
	'esri/geometry/Extent',
	'esri/geometry/Point',
	'esri/layers/GraphicsLayer',
], function(Map, WMTSLayer, WMTSLayerInfo, TileInfo, SpatialReference, Extent, Point, GraphicsLayer) {

	let mapCenterPoint = new Point(113.54053399503847, 34.820609606243906, new SpatialReference({
		wkid: 4326
	}));

	map = new Map('map', {
		logo: false,
	});

	map.on('load', function() {
		// 引入第三方插件
		require(['./plugins/Echarts3Layer.js'], function(Echarts3Layer) {
			setTimeout(() => {
				// 绘制热力图
				drawHeatmap()
			}, 500)
		})

	})

	import(`./options/initArcmap.js`).then(({
		default: layerObj
	}) => {
		// 添加天地图
		map.addLayer(layerObj.tdBaseLayer)
		map.addLayer(layerObj.tdBaseMarkerLayer)
	})

	// 定位到地图中心
	map.centerAndZoom(mapCenterPoint, 12);

})

/**
 * 绘制热力图
 */
function drawHeatmap() {
	// 获取热力图所有点
	$.get(`./data/water98.json`, function(data) {
		// 创建热力图对象
		if (!window.heatmap) {
			window.heatmap = Dcq.Heatmap.Instance();
		}
		if (!window.heatmap.isInited()) {
			// 初始化热力图对象，注入echarts实例和地图实例
			window.heatmap.init({
				'map': map,
				'echarts': echarts
			});
		}
		// 构建热力图数据
		const result = [];
		for (var i = 0; i < data.length; i++) {
			var item = data[i];
			// 经度、纬度、高程
			result.push([item.coord[0], item.coord[1], item.elevation]);
		}
		// 绘制热力图
		window.heatmap.drawChart(result);

	}, "json");

}
